import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { HydratedDocument } from 'mongoose';
import dayjs from 'dayjs';

@Schema()
export class User {
  @Prop({ required: true, unique: true })
  account: string;

  @Prop({ required: true })
  password: string;

  @Prop({ required: true })
  mobile: string;

  @Prop({ type: String, default: '' })
  name: string;

  @Prop({
    type: String,
    default: 'MALE',
    enum: ['MALE', 'FEMALE'] // 枚举类型，只能是MALE（男）或FEMALE（女）
  })
  sex: string;

  @Prop({ type: String, default: () => dayjs().format('YYYY-MM-DD') })
  birthday: string;

  @Prop({ type: Number, default: 0, min: 0, max: 120 })
  age: number;

  @Prop({ type: String, default: '' })
  email: string;

  @Prop({ type: String, default: '' })
  avatar: string;

  @Prop({ type: String, default: '0', enum: ['0', '1', '2', '3'] }) // 枚举类型，只能是0（普通会员）、1（白银会员）、2（黄金会员）或3（钻石会员）
  member: string;

  @Prop({ type: String, default: () => dayjs().format('YYYY-MM-DD HH:mm:ss') })
  createdAt: string;

  @Prop({ type: String, default: '' })
  updatedAt: string;
}

export type UserDocument = HydratedDocument<User>;

export const UserSchema = SchemaFactory.createForClass(User);

UserSchema.index({ account: 1 }, { unique: true }); // 根据account字段创建唯一索引
